package com.zeny.express.framework.log.service.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zeny.express.framework.log.dao.ActionLogEntityDao;
import com.zeny.express.framework.log.dao.BusinessLogDetailEntityDao;
import com.zeny.express.framework.log.dao.BusinessLogEntityDao;
import com.zeny.express.framework.log.entity.ActionLogEntity;
import com.zeny.express.framework.log.entity.BusinessLog;
import com.zeny.express.framework.log.entity.BusinessLogDetailEntity;
import com.zeny.express.framework.log.service.LogPersistenceService;

/**
 * 日志持久化服务
 * 
 * @author zhuwei
 * @date 2013年10月19日 下午6:07:15
 */
@Service
public class LogPersistenceServiceImpl implements LogPersistenceService {

	/**
	 * 日志
	 */
	private static final Logger LOGGER = LoggerFactory
			.getLogger(LogPersistenceServiceImpl.class);

	@Autowired(required = false)
	private ActionLogEntityDao actionLogEntityDao;

	@Autowired(required = false)
	private BusinessLogEntityDao businessLogEntityDao;

	@Autowired(required = false)
	private BusinessLogDetailEntityDao businessLogDetailEntityDao;

	@Override
	public void saveActionLog(ActionLogEntity entity) {

		if (actionLogEntityDao == null) {
			LOGGER.warn("saveActionLog, {}", entity.toString());
			return;
		}

		actionLogEntityDao.insert(entity);
	}

	@Override
	public void saveBusinessLog(BusinessLog entity) {

		if (businessLogEntityDao == null) {
			LOGGER.warn("saveBusinessLog, {}", entity.toString());
			return;
		}

		businessLogEntityDao.insert(entity);
		for (BusinessLogDetailEntity detail : entity.getDetails()) {
			businessLogDetailEntityDao.insert(detail);
		}
	}

}
